package com.example.arithmeticleetcode.leetcode.october;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-13 11:56
 **/
public class Demo04 {

    public static void main(String[] args) {
        int[] arr = {1,0,2,3,0,4,5,0};
        duplicateZeros(arr);
    }

    public static void duplicateZeros(int[] arr) {
        List<Integer> list = new ArrayList<>();
        for (int i : arr) {
            if (i == 0) {
                list.add(0);
                list.add(0);
            } else {
                list.add(i);
            }
        }
        for (int i = 0, len = arr.length; i < len; i++) {
            arr[i] = list.get(i);
        }
        //[1,0,0,2,3,0,0,4]
        System.out.println(Arrays.toString(arr));
    }
}
